<?php
use models\File as File;

include_once '!config.php';

$file = new File();
$smarty->assign('item', $_POST);
switch ($_GET['action']) {
    case 'createGlobalFilesBrowse'  :   $item['fileTypes'] = File::getFileTypes();
                                        $item['files'] = $file->read();
                                        $smarty->assign('item', $item);
                                        $templates = array('form/file/filesList.tpl','form/file/uploadPanel.tpl');
                                        $smarty->assign('templates',$templates);
                                        $response['content'] = $smarty->fetch('form/file/filesList.tpl');
                                        $response['content'] .= $smarty->fetch('form/file/uploadPanel.tpl');
                                        $response['status'] = 'OK!';
                                        echo json_encode($response);
                                        break;

    case 'upload'                   :   $file->upload($_POST['fileName'], $_POST['fieldId'], $_POST['itemId']);
                                        $smarty->assign('file', $file->newFile);
                                        $response['content'] = $smarty->fetch('form/file/file.tpl');
                                        $response['file'] = $file->newFile;
                                        $response['status'] = 'OK!';
                                        $response['relation'] = $file->relation;
                                        echo json_encode($response);
                                        break;


    case 'getJSON'                  :   echo $file->getJSON($_POST[id], $filedId);
                                        break;
    case 'setFileAlt'               :   $file->setFileAlt($_POST['id'],$_POST['fieldId'],$_POST['alt']);
                                        break;


    case 'delete'                   :   $file->delete($_POST['id'], $_POST['fieldId']);
                                        break;

    case 'imageRotate'              :   $file->imageRotate($_POST['id'], $_POST['fieldId']);
                                        $smarty->assign('file', $file->newFile);
                                        $smarty->display('form/file/type/image.tpl');
                                        break;

}
?>
